package
{
	import com.junkbyte.console.Cc;
	import com.junkbyte.console.addons.autoFocus.CommandLineAutoFocusAddon;
	import com.junkbyte.console.addons.displaymap.DisplayMapAddon;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.FileReference;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.utils.ByteArray;


	/**
	 *
	 * @author wardenfeng
	 * 2012-10-10上午10:43:23
	 *
	 */
	public class TestSwf extends Sprite
	{
		private var configXmlPath:String = "config.swf";

		public function TestSwf()
		{
			addEventListener(Event.ADDED_TO_STAGE,function(event:Event):void
			{
				initFlashConsole();
			});
			
			var loader:Loader = new Loader();
			loader.load(new URLRequest("http://static.kunlun.com/fsws/zhengshi/client/bin/GameLoader_7979.swf"));
			addChild(loader);
			
//			var ul:URLLoader = new URLLoader();
//			ul.dataFormat = URLLoaderDataFormat.BINARY;
//			ul.addEventListener(Event.COMPLETE, onComplete);
//			ul.load(new URLRequest("http://static.kunlun.com/fsws/zhengshi/client/bin/GameLoader_7979.swf"));
//			
//			var loader:Loader = new Loader();
//			addChild(loader);
//			
//			function onComplete(e:Event):void
//			{
//				var ba:ByteArray = (e.target as URLLoader).data;
//				
//				loader.loadBytes(ba);
//				
//				ba.compress(); //这里要代换成一个复杂的加工作业
//				var fr:FileReference = new FileReference();
//				//				fr.save(ba, "asset_c.swf");
//			}
		}

		/**
		 * 初始化控制台
		 **/
		public function initFlashConsole():void
		{
			//
			// SETUP - only required once
			//
			// you must modify the styles before starting console.
			Cc.config.style.big(); // BIGGER text. this modifies the config variables such as traceFontSize, menuFontSize
			Cc.config.style.whiteBase(); // Black on white. this modifies the config variables such as priority0, priority1, etc
			Cc.config.style.backgroundAlpha = 0.6; // makes it non-transparent background.
			
			Cc.startOnStage(this, "`"); // "`" - change for password. This will start hidden
			Cc.commandLine = true; // enable command line
			Cc.config.commandLineAllowed = true;
			
			Cc.width = stage.stageWidth;
			Cc.height = stage.stageHeight;
			
			DisplayMapAddon.registerCommand();
			DisplayMapAddon.addToMenu("DM"); // DisplayMapper. click on DM button at top menu to start.
			
			CommandLineAutoFocusAddon.registerToConsole(); // this addon auto focus to commandline when console becomes visible
		}
	}
}
